<?php
declare(strict_types=1);

namespace App\Service;

use App\Helper\Log;
use App\Helper\Util;
use Hyperf\DbConnection\Db;

/**
 * 班次服务
 */
class TradService 
{
    /**
     * 获取班次名词&颜色
     * [getTradNameAndColor description]
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function getTradNameAndColor($id)
    {
        $data = Db::table('office_trad')
            ->select(['name','color'])
            ->where(['id'=>$id])
            ->first();
        if(empty($data)){
            return NULL;
        }
        $data['color_code'] = Db::table('conf_color')
            ->where(['id'=>$data['color']])
            ->value("color");
        return $data;
    }
    /**
     * 获取班次详细信息
     * [getTradInfoMore description]
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function getTradInfoMore($id)
    {
        $data = Db::table('office_trad')
            ->select(['type','name','color','work_time','work_hours','coe'])
            ->where(['id'=>$id])
            ->first();
        if(empty($data)){
            return NULL;
        }
        $data['work_time'] = json_decode($data['work_time'],true);
        $data['color_code'] = Db::table('conf_color')
            ->where(['id'=>$data['color']])
            ->value("color");
        return $data;
    }
}
